package com.henry.imkit.utils

import android.util.Base64
import java.io.UnsupportedEncodingException

object Base64Utils {

    // 编码
    fun getBase64(str: String?): String {
        var result = ""
        if( str != null) {
            try {
                result = Base64.encodeToString(str.toByteArray(), Base64.NO_WRAP)
            } catch (e: UnsupportedEncodingException) {
                e.printStackTrace()
            }
        }
        return result
    }

    // 解码
    fun getFromBase64(str: String?): String {
        var result = ""
        if (str != null) {
            try {
                result = String(Base64.decode(str, Base64.NO_WRAP))
            } catch (e: UnsupportedEncodingException) {
                e.printStackTrace()
            }
        }
        return result
    }
}